﻿using AbpApplication.InPut;
using AbpToDomain.View;
using NewWms.Apiservice;
using NewWms.Apiservice.Dto;
using NewWms.Apiservice.InPut;
using NewWms.Views;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewWms.ViewModels
{
    public class ShelfManageViewModel : BindableBase, INavigationAware
    {
        private Prism.Services.Dialogs.IDialogService Dialog;
        private readonly ShelfManageView shelfManageView;
        public ShelfManageViewModel(Prism.Services.Dialogs.IDialogService dialog) 
        {
            Command=new DelegateCommand<string>(Method);
            DialogCommand=new DelegateCommand<string>(ShowDialog);
            SelectionChangedCommand = new DelegateCommand<Guid?>(SelectionChanged);
            viewService = new ViewService();
            baseService = new BaseService();
     
            WarehouseDtos = new List<WarehouseDto>();
            WarehouseLineDtos=new List<WarehouseLineDto>();
            InPut_ViewService3=new InPut_ViewService3();
            Dialog = dialog;
        }

        private long count;
        public long Count
        {
            get { return count; }
            set { count = value; RaisePropertyChanged(); }
        }
        private long pagecount;
        public long PageCount { get { return pagecount; }set { pagecount = value; RaisePropertyChanged(); } }
        private readonly IViewService viewService;
        private readonly IBaseService baseService;
        public DelegateCommand<string> Command { get; set; }
        public DelegateCommand<string> DialogCommand { get; set; }
        public DelegateCommand<string> ShowDialogCommand { get; set; }
        public DelegateCommand<Guid?> SelectionChangedCommand { get; set; }
        public List<WarehouseDto> warehouseDtos;
        public List<WarehouseDto> WarehouseDtos 
        { get { return warehouseDtos; } 
        set { warehouseDtos = value;RaisePropertyChanged(); } }
        private List<WarehouseLineDto> warehouseLineDtos;
        public List<WarehouseLineDto> WarehouseLineDtos
        {
            get { return warehouseLineDtos; }
            set { warehouseLineDtos = value; RaisePropertyChanged(); }
        }
        private InPut_ViewService3 inPut_ViewService3;
        public InPut_ViewService3 InPut_ViewService3
        {
            get { return inPut_ViewService3; }
            set { inPut_ViewService3 = value;RaisePropertyChanged(); }
        }


        public void Method(string Obj)
        {
            switch (Obj)
            {
                case "View_WareHouse":
                    View_WareHouse();break;
                case "View_WareHouseLine":
                    View_WareHouseLine();break;
            }
        }
        private void ShowDialog(string obj)
        {
            Dialog.ShowDialog(obj);

        }
        private async void View_WareHouse()
        {
            WarehouseDtos= await  viewService.View_WareHouse();
        }
        private async void View_WareHouseLine()
        {


            Tuple<List<WarehouseLineDto>, long?, long?> tuple = await viewService.View_WareHouseLine(InPut_ViewService3);
            if (tuple == null)
            {
                return;
            }
            WarehouseLineDtos = tuple.Item1;
            Count = (long)tuple.Item2;
            PageCount = (long)tuple.Item3;
        }
        private async void SelectionChanged(Guid? Id_Warehouse)
        {
         
            if (Id_Warehouse != null)
            {
                InPut_ViewService3.Id_Warehouse =Id_Warehouse;
            }
            Tuple<List<WarehouseLineDto>, long?, long?> tuple = await viewService.View_WareHouseLine(InPut_ViewService3);
            if (tuple == null)
            {
                return;
            }
            WarehouseLineDtos = tuple.Item1;
            Count = (long)tuple.Item2;
            PageCount = (long)tuple.Item3;
        }



        private string title = "货架管理";
        public string Title
        {
            get { return title; }
            set { title = value; RaisePropertyChanged(); }
        }
        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }
        public void OnNavigatedFrom(NavigationContext navigationContext)
        {

        }
        public void OnNavigatedTo(NavigationContext navigationContext)
        {

            View_WareHouse();

            InPut_ViewService3.PageIndex = 1;
            InPut_ViewService3.PageSize = 50;
            View_WareHouseLine();

        }
    }
}

